﻿using AutoMapper;
using Comm100.Application.Services;
using Comm100.Framework.Auditing;
using Comm100.Framework.Authorization;
using Comm100.Public.Audit;
using Bot.Application.Dto;
using Bot.Application.Services;
using Bot.Domain.Bo;
using Bot.Domain.Entities;
using Bot.Domain.Interfaces;
using System;
using System.Collections.Generic;
using System.Text;
using Bot.Domain;

namespace Bot.Application.AnswerInChannelAuthenticationRequests.Service
{
    public class AnswerInChannelAuthenticationRequestAppService : BaseAppService, IAnswerInChannelAuthenticationRequestAppService
    {
        private IAnswerInChannelAuthenticationRequestDomainService _domainService;

        public AnswerInChannelAuthenticationRequestAppService(IAnswerInChannelAuthenticationRequestDomainService domainService) : base()
        {
            this._domainService = domainService;
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELAUTHENTICATIONREQUEST, AuditAction.DESTROY)]
        public void Delete(Guid id)
        {
            _domainService.Delete(id);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELAUTHENTICATIONREQUEST, AuditAction.CREATE)]
        public AnswerInChannelAuthenticationRequestDto Add(Guid answerInChannelId, AnswerInChannelAuthenticationRequestCreateDto dto)
        {
            AnswerInChannelAuthenticationRequest answerInChannelAuthenticationRequest = _domainService.CreateWithAnswerInChannelId(answerInChannelId, Mapper.Map<AnswerInChannelAuthenticationRequest>(dto));
            return Mapper.Map<AnswerInChannelAuthenticationRequestDto>(answerInChannelAuthenticationRequest);
        }

        [Authorization(BotPermission.MANAGE_BOTS)]
        //[Audit(BotEntity.ANSWERINCHANNELAUTHENTICATIONREQUEST, AuditAction.UPDATE)]
        public AnswerInChannelAuthenticationRequestDto Update(Guid id, AnswerInChannelAuthenticationRequestUpdateDto dto)
        {
            AnswerInChannelAuthenticationRequest answerInChannelAuthenticationRequest = _domainService.Update(Mapper.Map<AnswerInChannelAuthenticationRequestUpdateBo>(dto));
            answerInChannelAuthenticationRequest.Id = id;
            return Mapper.Map<AnswerInChannelAuthenticationRequestDto>(answerInChannelAuthenticationRequest);
        }

        public AnswerInChannelAuthenticationRequestDto Get(Guid id)
        {
            AnswerInChannelAuthenticationRequest answerInChannelAuthenticationRequest = _domainService.Get(id);
            return Mapper.Map<AnswerInChannelAuthenticationRequestDto>(answerInChannelAuthenticationRequest);
        } 
        public AnswerInChannelAuthenticationRequestDto GetByAnswerInChannelId(Guid answerInChannelId)
        {
            AnswerInChannelAuthenticationRequest answerInChannelAuthenticationRequest = _domainService.GetByAnswerInChannelId(answerInChannelId);
            return Mapper.Map<AnswerInChannelAuthenticationRequestDto>(answerInChannelAuthenticationRequest);
        }

        public IEnumerable<AnswerInChannelAuthenticationRequestDto> GetList()
        {
            IEnumerable<AnswerInChannelAuthenticationRequest> list = _domainService.List();
            return Mapper.Map<IEnumerable<AnswerInChannelAuthenticationRequestDto>>(list);
        }
    }
}
